<div class="loading-container"><div class="loader"></div></div>

<div class="loading-waiter">
	<div class="loader">
		<div class="texting">请稍后...</div>
		<div class="spinner">
		  <div class="rect1"></div>
		  <div class="rect2"></div>
		  <div class="rect3"></div>
		  <div class="rect4"></div>
		  <div class="rect5"></div>
		</div>
	</div>
</div>

<div class="wrapper wrapper-shadow wrapper-list"> 
	<!-- list data wrapper -->
	<div class="result-wrapper no-padding">
   	<div class="result-body">
   		<div class="tabs">
      	<ul class="nav nav-tabs widget no-margin-bottom">
        	<li class="active"> 
         		<a href="#tab-content" data-toggle="tab"> 
         			<span class="menu-icon"><i class="fa fa-bar-chart"></i></span>综合查询
           	</a>
         	</li>
        </ul>
        <div class="tab-content no-border xs-padding">
					<div class="tab-pane active" id="tab-content" style="padding:10px 0;">
           	<div class="search-panel" style="margin-bottom: 10px;">
           		<form class="form-inline" id="select-form" >
							  <div class="form-group">
							    <label for="adviser">销售顾问：</label>
							    <div class="input-group" style="width: 200px;">
										<select id="adviser" class="chosen-select" style="width: 200px;" data-entity="com.app.miwawa.api.esm.entity.view.AdviserView">
											<option value="">请选择...</option>
										</select>
									</div>
									
									&nbsp;&nbsp;
									
									<label for="from">市场渠道：</label>
							    <div class="input-group" style="width: 200px;">
										<select id="market" class="chosen-select"  data-url="/miwawa/default/common/select.json" data-pcode="c_market_type" data-entity="com.app.miwawa.api.system.entity.config.Codec">
											<option value="">请选择...</option>
										</select>
									</div>
									
									&nbsp;&nbsp;

									<label for="from">信息来源：</label>
							    <div class="input-group" style="width: 200px;">
								    <select id="source" class="chosen-select" style="width: 200px;" data-url="/miwawa/default/common/select.json" data-pcode="c_source_type" data-entity="com.app.miwawa.api.system.entity.config.Codec">
											<option value="">请选择...</option>
										</select>
									</div>
								
								</div>
								
								<div class="vertical-space space-5"></div>
							  
							  <div class="form-group">
							  
							  	<label for="student">宝宝姓名：</label>
							    <div class="input-group">
								    <input id="student" type="text" class="form-control" placeholder="请输入宝宝姓名" style="width:200px;">
									</div>
									
							  	&nbsp;&nbsp;
							  	
							    <label for="parent">家长姓名：</label>
							    <div class="input-group">
								    <input id="parent" type="text" class="form-control" placeholder="请输入家长姓名" style="width:200px;">
									</div>
									
									&nbsp;&nbsp;
									
									<label for="mobile">手机号码：</label>
							    <div class="input-group">
								    <input id="mobile" type="text" class="form-control" placeholder="请输入手机号码" style="width:200px;">
									</div>
									
							  </div>
							  
							  <div class="vertical-space space-5"></div>
							  
							  <div class="form-group">
							  	
							  		<label for="from">宝宝生日：</label>
							    <div class="input-group date date-selector">
										<input id="from" type="text" class="form-control" style="width: 198px;"> 
										<span class="input-group-addon">
											<span class="fa fa-calendar"></span>
										</span>
									</div>
									<span>-</span>
									<div class="input-group date date-selector">
										<input id="over" type="text" class="form-control" style="width: 198px;"> 
										<span class="input-group-addon">
											<span class="fa fa-calendar"></span>
										</span>
									</div>	
							  	
							  	&nbsp;&nbsp;
									<button type="button" class="btn btn-warning" onclick="handlerReset();">重置</button>
									&nbsp;&nbsp;
									<button type="button" class="btn btn-primary" onclick="handlerSelect();">查询</button>
							  </div>
							  
           		</form>
           	</div>
           	
           	<div id="table-a1">
           		<table data-ajax="handlerSearch" 
           				 data-method="post" 
           				 data-toolbar="#toolbar" 
           				 data-id-field="id" 
           				 data-unique-id="id" 
           				 data-pagination="true" 
           				 data-check-on-init="true" 
           				 data-side-pagination="server" 
           				 data-mobile-responsive="true" 
           				 data-event-onload="handlerSuccess" 
           				 data-form-search="#search-form-allCustomer" id="table-allCustomer" class="bootstrap-table">
							<thead>
								<tr>
									<th data-field="id"						data-visible="false" data-switchable="false">ID</th>
									<th data-field="status" 			data-align="center" data-formatter="renderStatus">会员类型</th>
									<th data-field="invalid" 			data-align="center" data-formatter="renderInvalid">位置</th>
									<th data-field="createDate" 	data-align="center" data-sortable="true">登记时间</th>
									<th data-field="username" 		data-align="center" data-sortable="true">顾问</th>
									<th data-field="student" 			data-align="center" >宝宝</th>
									<th data-field="birthday" 		data-align="center" data-sortable="true">生日</th>
									<th data-field="moonage" 			data-align="center" data-sortable="true">月龄</th>
									<th data-field="relation" 		data-align="center" >关系</th>
									<th data-field="parent" 			data-align="center" data-sortable="true">家长姓名</th>
									<th data-field="mobile" 			data-align="center" data-sortable="true">联系方式</th>
									<th data-field="market" 			data-align="center" data-sortable="true">渠道</th>
									<th data-field="source" 			data-align="center" data-sortable="true">来源</th>
									<th data-field="operator" 		data-align="center" data-width="40" data-formatter="renderOperator" data-table-target="customer">操作</th>
								</tr>
							</thead>
						</table>
           	</div>
        	</div>
      	</div>
    	</div>
   	</div>
	</div>

	<!-- form editor wrapper -->
	<div class="editor-wrapper">
		
	</div>
</div>

<!-- PAGE CONTENT END =============================================== -->
<!-- 查询 表单 ========================================================= -->
<form id="search-form-allCustomer" action="/miwawa/{dbname}/common/search.json" method="post" 
			name="com.app.miwawa.api.esm.entity.view.CustomerView">
			<input type="hidden" name="invalid" value="T" data-search-group="and" data-search-operation="EQ"/>
			<input type="hidden" data-search-sort="createDate" 	data-search-order="desc"/>
			<input type="hidden" data-search-sort="id" 					data-search-order="asc"/>
</form>

<!-- 删除表单================================== -->
<form id="remove-form-selling" 	action="/miwawa/{dbname}/common/remove" 	method="post" name="com.app.miwawa.api.esm.entity.customer.Selling"></form>
<form id="remove-form-bespoke" 	action="/miwawa/{dbname}/common/remove" 	method="post" name="com.app.miwawa.api.esm.entity.customer.Bespoke"></form>

<!-- Javascript ===================================================== -->
<script src="/miwawa/resources/lib/miwawa/1.0.2/js/core/requirejs/require.js"></script>

<script type="text/javascript">
<!--
	var $form;
	
	jQuery(function(){
		require(['jquery.plugin.form'],function(form){
			$form = form;
			form.datepicker(".date-selector",{defaultDate:null});
			form.tooltip("[data-toggle='tooltip']");
			form.chosen("#adviser").select("#adviser",{querys:{"invalid_EQ":"F"}});
			form.chosen("#market").select("#market");
			form.chosen("#source").select("#source");
		});
		require(['/miwawa/resources/lib/miwawa/1.0.2/js/core/module/app/simple.js'], function(simple){
			simple(['registerForm','registerWidget']);
		});
		handlerSuccess();
		// 加载学员列表
		jQuery("#table-allCustomer").bootstrapTable({
			sortable: true
		});
	});
	
	//清空多选下拉框
	function handlerClear(elem){
		jQuery(".search-choice .search-choice-close", elem+"_chosen").click();
	}
	
	// 重置查询条件
	function handlerReset(){
		jQuery("#select-form").resetForm();
		
		jQuery(".chosen-single span").text("请选择...");
	}
	
 	function renderStatus(value, row, index){
 		if(value =="member" || value =="expire"){
 			return "会员";
 		}else{
 			return "非会员";
 		}
 	}
 	
	function renderInvalid(value, row, index){
		if(row.status == "follows"){
			return "跟进的";
		}else if(row.status == "0"){
			return "新增的";
		}else if(row.status == "promise"){
			return "诺访的";
		}else if(row.status == "comming"){
			return "到店的";
		}else if(row.status == "losted"){
			return "流失的";
		}else if(row.status == "member"){
			return "有效的";
		}else{
			return "过期的";
		}
	}
	
	// 渲染列表操作列
	function renderOperator(value, row, index){
		var operator = "";
		switch(this.tableTarget){
			case "customer":
				operator += "<a class='btn btn-info btn-xs btn-table-op' onclick='handlerCreate(this,\""+row.id+"\")' data-table-source='#table-allCustomer' data-editor-path='/miwawa/content/esm/select/editor' data-editor-page='edit.html' data-toggle='tooltip' data-placement='top' title='查看与跟进'> <i class='icon-call-out'></i> </a>"				 	 				 										
			break;
			case "selling":
				if(row.id != "new"){
					operator = "<a class='btn btn-danger btn-xs btn-table-op' data-toggle='tooltip' data-placement='top' title='删除' onclick='handlerRemove(this, \""+row.id+"\")' data-table-source='#table-selling' data-form-source='#remove-form-selling'> <i class='fa fa-trash'></i> </a>";
				}else{
					operator = value;
				}
			break;
			case "bespoke":
				if(row.id == "new" || row.id == "edit"){
					operator = value;
				}else{
					operator = "<a class='btn btn-info	btn-xs btn-table-op' id='edited' onclick='editBespoke(this,\""+index+"\")' data-table-source='#table-bespoke' data-rowdata='"+JSON.stringify(row)+"' data-toggle='tooltip' data-placement='top' title='修改'> <i class='ion-compose'></i> </a>"
					 + "<a class='btn btn-danger btn-xs btn-table-op' data-toggle='tooltip' data-placement='top' title='删除' onclick='handlerRemove(this, \""+row.id+"\")' data-table-source='#table-bespoke' data-form-source='#remove-form-bespoke'> <i class='fa fa-trash'></i> </a>";
				}
			break;
		}
		return operator;
	}
	
	function handlerSelect(){
		//清空查询条件
		jQuery("#search-form-allCustomer").empty();
		
		//顾问
		if(jQuery("#adviser").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='userid' value='"+jQuery("#adviser").val()+"' data-search-group='and' data-search-operation='EQ'>");
		}
		//宝宝生日起始
		if(jQuery("#from").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='birthday' value='"+jQuery("#from").val()+"' data-search-group='and' data-search-operation='GE' data-search-type='DATES'>");
		}
		//宝宝生日结束
		if(jQuery("#over").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='birthday' value='"+jQuery("#over").val()+"' data-search-group='and' data-search-operation='LE' data-search-type='DATES'>");
		}
		//宝宝
		if(jQuery("#student").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='student' value='"+jQuery("#student").val()+"' data-search-group='and' data-search-operation='LIKE'>");
		}
		//家长姓名
		if(jQuery("#parent").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='parent'  value='"+jQuery("#parent").val()+"'  data-search-group='and' data-search-operation='LIKE'>");
		}
		//手机号
		if(jQuery("#mobile").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='mobile' value='"+jQuery("#mobile").val()+"' data-search-group='and' data-search-operation='EQ'>");
		}
		//市场渠道
		if(jQuery("#market").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='market' value='"+jQuery("#market").val()+"' data-search-group='and' data-search-operation='EQ'>");
		}
		//信息来源
		if(jQuery("#source").val() != ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='source' value='"+jQuery("#source").val()+"' data-search-group='and' data-search-operation='EQ'>");
		}
		
		//家长姓名
		if(jQuery("#parent").val() == "" && jQuery("#mobile").val() == ""){
			jQuery("#search-form-allCustomer").append("<input type='hidden' name='isparent' value='true' data-search-group='and' data-search-operation='EQ'>");
		}
		jQuery("#search-form-allCustomer").append("<input type='hidden' data-search-sort='createDate' 	data-search-order='desc'/> <input type='hidden' data-search-sort='id' data-search-order='asc'/>");
		
		jQuery("#table-allCustomer").bootstrapTable("refresh");
	}
	
	
//-->
</script>